/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.fi.muni.pa165.hotelbookingmanager.ejb;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

/**
 *
 * @author Andrej Galád
 */
@Stateless
@Local(value = ClientService.class)
public class ClientServiceImpl implements ClientService {

    @EJB
    private ClientDAO clientDAO;

    @Override
    public void createClient(Client client) {
        if (client == null)
            throw new IllegalArgumentException("client cannot be null");
        if (client.getId() != null)
            throw new IllegalArgumentException("client cannot have manually assigned id");
        // tu dorobit validaciu
        clientDAO.create(client);
    }

    @Override
    public Client findClient(Long id) {
        if (id == null)
            throw new IllegalArgumentException("id cannot be null");
        return clientDAO.get(id);
    }

    @Override
    public void updateClient(Client client) {
        if (client == null)
            throw new IllegalArgumentException("client cannot be null");
        if (client.getId() == null || clientDAO.get(client.getId()) == null)
            throw new IllegalArgumentException("trying to update non-existent client");
        // tu dorobit validaciu
        clientDAO.update(client);
    }

    @Override
    public void deleteClient(Client client) {
        if (client == null)
            throw new IllegalArgumentException("client cannot be null");
        clientDAO.delete(client);
    }

    @Override
    public List<Client> findAllClients() {
        return clientDAO.findAll();
    }

    public void setDAO(ClientDAO dao) {
        clientDAO = dao;
    }
}
